﻿using System;
using System.Collections.Generic;
using System.Text;

namespace QRCodePass.Application
{
   public class OperateResult
    {

        public int Code { get; set; } = 200;
        public string Message { get; set; }
        public bool Succeeded { get; set; }

        public static readonly OperateResult Success = new OperateResult()
        {
            Succeeded = true,
            Message = "Success"
        };

        /// <summary>
        /// 默认400，指定错误信息
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static OperateResult Failed(string message = "参数为空")
        {
            return new OperateResult()
            {
                Succeeded = false,
                Code = 400,
                Message = message
            };
        }

        /// <summary>
        /// 指定错误代码和信息
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static OperateResult Failed(int code, string message)
        {
            return new OperateResult()
            {
                Succeeded = false,
                Code = code,
                Message = message
            };
        }

        /// <summary>
        /// 默认400，指定错误信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="message"></param>
        /// <returns></returns>
        public static OperateResult<T> Failed<T>(string message)
        {
            return new OperateResult<T>()
            {
                Succeeded = false,
                Code = 400,
                Message = message
            };
        }

        /// <summary>
        /// 指定错误代码和错误信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="message"></param>
        /// <returns></returns>
        public static OperateResult<T> Failed<T>(int code, string message)
        {
            return new OperateResult<T>()
            {
                Succeeded = false,
                Code = code,
                Message = message
            };
        }

        public static OperateResult<T> Successed<T>(T data)
        {
            return new OperateResult<T>()
            {
                Code = 200,
                Message = "Success",
                Succeeded = true,
                Data = data
            };
        }

        public static OperateResult<T> Successed<T>(T data, string message)
        {
            return new OperateResult<T>()
            {
                Code = 200,
                Message = message,
                Succeeded = true,
                Data = data
            };
        }
        public static OperateResult SuccessedWithMessgae(string message)
        {
            return new OperateResult()
            {
                Code = 200,
                Message = message,
                Succeeded = true,
            };
        }

    }
    public class OperateResult<T> : OperateResult
    {
        public T Data { get; set; }
    }
}

